home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 1372.ZIP / LITECOMM.ARC / TTL.PAS < prev   
Pascal/Delphi Source File  |  1988-06-27  |  20KB  |  827 lines

  1. {$R-,S-,I+,D-,T-,F-,V-,B-,N-,L+ }
  2. {$M 16384,0,655360 }
  3. (*
  4. **  TTL is a complete, if somewhat limited, terminal emulation
  5. **  program  designed to demonstrate the use of the LiteComm
  6. **  ToolBox.  The executable version is included so that you can
  7. **  try it out while viewing the code.  To successfully create a
  8. **  new version of TTL, you must have the XMODEM engine
  9. **  which is provided as part of your registration package.
  10. **  While non-registered users cannot create a new version of TTL,
  11. **  you may still examine the TTL program, and use it as a basis for
  12. **  your own programming.
  13. **
  14. **  Information Technology, Ltd.
  15. *)
  16.  
  17. program TTL;
  18.  
  19. uses
  20.   DOS, LctKrnl, LctSupp, LtXMKrnl, LtXmodem, LwXModem, Crt;
  21.  
  22. const
  23.   CPort    : integer = 2;
  24.   Baud     : integer = 2400;
  25.   Parity   : char = 'N';
  26.   Databits : integer = 8;
  27.   Stopbits : integer = 1;
  28.   Yxmode   : boolean = false;
  29.   Wxmode   : boolean = false;
  30.   Halfd    : boolean = false;
  31.   Hostm    : boolean = false;
  32.   CPtr     : CCBPTR = NIL;
  33.   Imask    : byte = $00;
  34.  
  35. type
  36.   FnStr = string[64];
  37.  
  38. procedure GetFileName(var FName : FnStr);
  39.  
  40. begin
  41.   Writeln;
  42.   Write('Enter File Name: ');
  43.   FName := '';
  44.   Readln(FName);
  45. end;                                    { GetFileName }
  46.  
  47. procedure XSend;
  48. var
  49.   SFile     : file;
  50.   SFilename : FnStr;
  51.   Buffer    : array[1..1024] of byte;
  52.   BufNdx    : integer;
  53.   Result    : XMResult;
  54.   ToRead    : integer;
  55.   ToSend    : integer;
  56.   FRes      : integer;
  57.  
  58. begin
  59.   Writeln;
  60.   Writeln('Sending a File');
  61.   GetFileName(SFileName);
  62.   if Length(SFilename) = 0 then
  63.   begin
  64.     Writeln('Zero Length Name entered');
  65.     ReadLn;
  66.     exit;                                { nothing to send }
  67.   end;
  68.  
  69.   Assign(SFile, SFilename);
  70. {$I-}
  71.   Reset(SFile, 1);                     { attempt to open }
  72. {$I+}
  73.   FRes := IOResult;
  74.   if FRes <> 0 then
  75.   begin
  76.     Writeln('Error Opening file: ',FRes);
  77.     ReadLn;
  78.     exit;
  79.   end;
  80.  
  81.   if not CommSetup(CPort, Baud, 'N', 8, 1) then
  82.   begin
  83.     Writeln('Unable to change Port parameters, <RET> to continue');
  84.     Readln;
  85.     exit;
  86.   end;
  87.  
  88. {
  89.   Transmit the file using the engine
  90. }
  91.   if YModem then
  92.     ToRead := 1024
  93.   else
  94.     ToRead := 128;
  95.   Result := Success;
  96.   FRes := 1;
  97.   while (FRes > 0) and
  98.         (Result = Success) do
  99.   begin
  100.     FillChar(Buffer, Sizeof(Buffer), $00);
  101. {$I-}
  102.     BlockRead(SFile, Buffer, ToRead, FRes);
  103. {$I+}
  104.     BufNdx := 1;
  105.     if FRes = 0 then                   {EOF Signal ?}
  106.       FRes := -1;
  107.  
  108.     while (FRes > 0) and
  109.           (Result = Success) do
  110.     begin
  111.       if Yxmode then
  112.         if FRes <> ToRead then         { short block }
  113.         begin
  114.           ToRead := 128;               { sending short }
  115.           YModem := false;
  116.         end;;
  117.  
  118.       Result := LxmTrec(CPort, Buffer[BufNdx]);   { do actual transmission }
  119.  
  120.       case Result of
  121.         Success : begin
  122.                     Write('Sent Record: ', (RecNum - 1), ^M);
  123.                     Dec(FRes, ToRead);
  124.                     Inc(BufNdx, ToRead);
  125.                   end;
  126.         InitCan  : begin
  127.                      Writeln;
  128.                      Writeln('Cancel Req. INIT, <RET> to continue');
  129.                      Readln;
  130.                    end;
  131.         InitFail : begin
  132.                      Writeln;
  133.                      Writeln('Too many retries INIT, <RET> to continue');
  134.                      Readln;
  135.                    end;
  136.         CanReq  : begin
  137.                     Writeln;
  138.                     Writeln('Cancel Requested, <RET> to continue');
  139.                     Readln;
  140.                   end;
  141.         Retry   : begin
  142.                     Writeln;
  143.                     Writeln('Too Many Tries, Record: ', (RecNum - 1));
  144.                     Readln;
  145.                   end;
  146.         else
  147.           Writeln;
  148.           Writeln('Fatal Transmission Error, <RET> to continue');
  149.           Readln;
  150.       end;                             { case }
  151.     end;                               { inner while }
  152.     if Result = Success then
  153.       if FRes <> -1 then
  154.         FRes := 1;
  155.   end;                                 { outer while }
  156.  
  157.   if Result = Success then
  158.   begin
  159.     Result := LxmTeot(CPort);
  160.     if Result <> Success then
  161.     begin
  162.       Writeln('Error Ending Transmission');
  163.       Readln;
  164.     end;
  165.   end;
  166.  
  167.   if not CommSetup(CPort, Baud, Parity, Databits, Stopbits) then
  168.   begin
  169.     Writeln('Unable to Reset Port parameters, <RET> to continue');
  170.     Readln;
  171.   end;
  172. end;                                   { XSend }
  173.  
  174. procedure WxSend;
  175. var
  176.   SFile     : file;
  177.   SFilename : FnStr;
  178.   Buffer    : array[1..128] of byte;
  179.   BufNdx    : integer;
  180.   Result    : XMResult;
  181.   ToRead    : integer;
  182.   ToSend    : integer;
  183.   FRes      : integer;
  184.   NRec      : integer;
  185.  
  186. begin
  187.   Writeln;
  188.   Writeln('Sending a File');
  189.   GetFileName(SFileName);
  190.   if Length(SFilename) = 0 then
  191.   begin
  192.     Writeln('Zero Length Name entered');
  193.     ReadLn;
  194.     exit;                                { nothing to send }
  195.   end;
  196.  
  197.   Assign(SFile, SFilename);
  198. {$I-}
  199.   Reset(SFile, 128);                    { attempt to open }
  200. {$I+}
  201.   FRes := IOResult;
  202.   if FRes <> 0 then
  203.   begin
  204.     Writeln('Error Opening file: ',FRes);
  205.     ReadLn;
  206.     exit;
  207.   end;
  208.  
  209.   if not CommSetup(CPort, Baud, 'N', 8, 1) then
  210.   begin
  211.     Writeln('Unable to change Port parameters, <RET> to continue');
  212.     Readln;
  213.     exit;
  214.   end;
  215.  
  216.   if not EnableXon(CPort, true) then
  217.   begin
  218.     Writeln('Unable to turn on XON-XOFF, <RET> to continue');
  219.     Readln;
  220.     exit;
  221.   end;
  222.  
  223. {
  224.   Transmit the file using the engine
  225. }
  226.   Result := Success;
  227.   NRec := 0;
  228.  
  229.   while (NRec >= 0) and
  230.         ((Result = Success) or (Result = ReSend)) do
  231.   begin
  232.     if not Eof(SFile) then
  233.     begin
  234.       FillChar(Buffer, Sizeof(Buffer), $1A);
  235. {$I-}
  236.       BlockRead(SFile, Buffer, 1, FRes);
  237. {$I+}
  238.       NRec := 0;
  239.     end
  240.     else
  241.       NRec := -1;                       { signal EOF }
  242.  
  243.     Result := LwxTrec(CPort, Buffer, NRec);   { do actual transmission }
  244.  
  245.     case Result of
  246.       Success : if NRec <> -1 then
  247.                 begin
  248.                   Write('Sent Record: ', (RecNum - 1), ^M);
  249.                   Dec(FRes, ToRead);
  250.                   Inc(BufNdx, ToRead);
  251.                 end;
  252.       InitCan  : begin
  253.                    Writeln;
  254.                    Writeln('Cancel Req. INIT, <RET> to continue');
  255.                    Readln;
  256.                  end;
  257.       InitFail : begin
  258.                    Writeln;
  259.                    Writeln('Too many retries INIT, <RET> to continue');
  260.                    Readln;
  261.                  end;
  262.       CanReq  : begin
  263.                   Writeln;
  264.                   Writeln('Cancel Requested, <RET> to continue');
  265.                   Readln;
  266.                 end;
  267.       Retry   : begin
  268.                   Writeln;
  269.                   Writeln('Too Many Tries, Record: ', (RecNum - 1));
  270.                   Readln;
  271.                 end;
  272.       ReSend  : Seek(SFile, NRec*128);         { reposition the file }
  273.       else
  274.         Writeln;
  275.         Writeln('Fatal Transmission Error, <RET> to continue');
  276.         Readln;
  277.     end;                             { case }
  278.   end;                                 { outer while }
  279.  
  280.   Close(SFile);
  281.  
  282.   if not EnableXon(CPort, false) then
  283.   begin
  284.     Writeln('Unable to turn off XON-XOFF, <RET> to continue');
  285.     Readln;
  286.     exit;
  287.   end;
  288.   if not CommSetup(CPort, Baud, Parity, Databits, Stopbits) then
  289.   begin
  290.     Writeln('Unable to Reset Port parameters, <RET> to continue');
  291.     Readln;
  292.   end;
  293.  
  294. end;                                   { WxSend }
  295.  
  296. procedure SendFile;
  297. begin
  298.   if Yxmode then
  299.   begin
  300.     YModem := true;
  301.     XSend;
  302.   end
  303.   else
  304.   begin
  305.     YModem := false;
  306.     if Wxmode then                     { No, What type od XModem }
  307.       WXSend
  308.     else
  309.       XSend;
  310.   end;
  311. end;
  312.  
  313. procedure WxRecv;
  314. var
  315.   RFile     : file;
  316.   RFilename : FnStr;
  317.   Buffer    : array[1..128] of byte;
  318.   Result    : XMResult;
  319.   FRes      : word;
  320.  
  321. begin
  322.   Writeln;
  323.   Writeln('Receiving a File - WXModem');
  324.   GetFileName(RFileName);
  325.   if Length(RFilename) = 0 then
  326.   begin
  327.     Writeln('Zero Length Name entered');
  328.     ReadLn;
  329.     exit;                                { nothing to send }
  330.   end;
  331.  
  332.   Assign(RFile, RFilename);
  333. {$I-}
  334.   Rewrite(RFile, 1);                     { attempt to open }
  335. {$I+}
  336.   FRes := IOResult;
  337.   if FRes <> 0 then
  338.   begin
  339.     Writeln('Error Creating file: ',FRes);
  340.     ReadLn;
  341.     exit;
  342.   end;
  343.  
  344.   if not CommSetup(CPort, Baud, 'N', 8, 1) then
  345.   begin
  346.     Writeln('Unable to change Port parameters, <RET> to continue');
  347.     Readln;
  348.     exit;
  349.   end;
  350.  
  351. {
  352.   Transmit the file using the engine
  353. }
  354.   Result := Success;
  355.  
  356.   while (Result = Success) or
  357.         (Result = DupBlk) do
  358.   begin
  359.     FillChar(Buffer, 128, $00);
  360.     Result := LwxRrec(CPort, Buffer); { receive a block }
  361.  
  362.     case Result of
  363.       Success : begin
  364. {$I-}
  365.                   BlockWrite(RFile, Buffer, 128, FRes);
  366. {$I+}
  367.                   Write('Received Record: ', (RecNum - 1), ^M);
  368.                 end;
  369.       DupBlk  : begin
  370.                   Writeln;
  371.                   Writeln('Duplicate Block, ignored');
  372.                 end;
  373.       SeqErr  : begin
  374.                   Writeln;
  375.                   Writeln('Block Seq Error');
  376.                   Readln;
  377.                 end;
  378.       InitCan  : begin
  379.                   Writeln;
  380.                   Writeln('Cancel Req. INIT, <RET> to continue');
  381.                   Readln;
  382.                 end;
  383.       InitFail : begin
  384.                   Writeln;
  385.                   Writeln('Too many retries INIT, <RET> to continue');
  386.                   Readln;
  387.                 end;
  388.       CanReq  : begin
  389.                   Writeln;
  390.                   Writeln('Cancel Requested, <RET> to continue');
  391.                   Readln;
  392.                 end;
  393.       Retry   : begin
  394.                   Writeln;
  395.                   Writeln('Too Many Tries, Record: ', (RecNum - 1));
  396.                   Readln;
  397.                 end;
  398.       EndFile : begin
  399.                   Writeln;
  400.                   Writeln('Normal End, <RET> to continue');
  401.                   Readln;
  402.                 end;
  403.       TimeOut : begin
  404.                   Writeln;
  405.                   Writeln('SOH Timeout, <RET> to continue');
  406.                   Readln;
  407.                 end;
  408.       else
  409.         Writeln;
  410.         Writeln('Fatal Transmission Error, <RET> to continue');
  411.         Readln;
  412.     end;
  413.   end;
  414.  
  415.   Close(RFile);
  416.  
  417.   if not CommSetup(CPort, Baud, Parity, Databits, Stopbits) then
  418.   begin
  419.     Writeln('Unable to Reset Port parameters, <RET> to continue');
  420.     Readln;
  421.   end;
  422. end;                                   { WxRecv }
  423.  
  424. procedure XRecv;
  425. var
  426.   RFile     : file;
  427.   RFilename : FnStr;
  428.   Buffer    : array[1..1024] of byte;    { allow for YModem }
  429.   Result    : XMResult;
  430.   HandShake : byte;
  431.   RecdSize  : integer;
  432.   FRes      : word;
  433.  
  434. begin
  435.   Writeln;
  436.   Writeln('Receiving a File');
  437.   GetFileName(RFileName);
  438.   if Length(RFilename) = 0 then
  439.   begin
  440.     Writeln('Zero Length Name entered');
  441.     ReadLn;
  442.     exit;                                { nothing to send }
  443.   end;
  444.  
  445.   Assign(RFile, RFilename);
  446. {$I-}
  447.   Rewrite(RFile, 1);                     { attempt to open }
  448. {$I+}
  449.   FRes := IOResult;
  450.   if FRes <> 0 then
  451.   begin
  452.     Writeln('Error Creating file: ',FRes);
  453.     ReadLn;
  454.     exit;
  455.   end;
  456.  
  457.   if not CommSetup(CPort, Baud, 'N', 8, 1) then
  458.   begin
  459.     Writeln('Unable to change Port parameters, <RET> to continue');
  460.     Readln;
  461.     exit;
  462.   end;
  463.  
  464. {
  465.   Transmit the file using the engine
  466. }
  467.   Result := Success;
  468.   HandShake := CRCREQ;                 { Spec Checksum Mode }
  469.  
  470.   while (Result = Success) or
  471.         (Result = DupBlk) do
  472.   begin
  473.     FillChar(Buffer, TBSIZE, $00);
  474.     Result := LxmRrec(CPort, Buffer, RecdSize, RTOUT, HandShake); { receive a block }
  475.  
  476.     case Result of
  477.       Success : begin
  478. {$I-}
  479.                   BlockWrite(RFile, Buffer, RecdSize, FRes);
  480. {$I+}
  481.                   Write('Received Record: ', (RecNum - 1), ^M);
  482.                 end;
  483.       DupBlk  : begin
  484.                   Writeln;
  485.                   Writeln('Duplicate Block, ignored');
  486.                 end;
  487.       SeqErr  : begin
  488.                   Writeln;
  489.                   Writeln('Block Seq Error');
  490.                   Readln;
  491.                 end;
  492.       InitCan  : begin
  493.                   Writeln;
  494.                   Writeln('Cancel Req. INIT, <RET> to continue');
  495.                   Readln;
  496.                 end;
  497.       InitFail : begin
  498.                   Writeln;
  499.                   Writeln('Too many retries INIT, <RET> to continue');
  500.                   Readln;
  501.                 end;
  502.       CanReq  : begin
  503.                   Writeln;
  504.                   Writeln('Cancel Requested, <RET> to continue');
  505.                   Readln;
  506.                 end;
  507.       Retry   : begin
  508.                   Writeln;
  509.                   Writeln('Too Many Tries, Record: ', (RecNum - 1));
  510.                   Readln;
  511.                 end;
  512.       EndFile : begin
  513.                   Writeln;
  514.                   Writeln('Normal End, <RET> to continue');
  515.                   Readln;
  516.                 end;
  517.       TimeOut : begin
  518.                   Writeln;
  519.                   Writeln('SOH Timeout, <RET> to continue');
  520.                   Readln;
  521.                 end;
  522.       else
  523.         Writeln;
  524.         Writeln('Fatal Transmission Error, <RET> to continue');
  525.         Readln;
  526.     end;
  527.   end;
  528.  
  529.   Close(RFile);
  530.  
  531.   if not CommSetup(CPort, Baud, Parity, Databits, Stopbits) then
  532.   begin
  533.     Writeln('Unable to Reset Port parameters, <RET> to continue');
  534.     Readln;
  535.   end;
  536. end;                                   { XRecv }
  537.  
  538. procedure ReceiveFile;
  539. begin
  540.   if not Yxmode then                   { Y Modem specified }
  541.     if Wxmode then                     { No, What type od XModem }
  542.       WXRecv
  543.     else
  544.       XRecv
  545.   else
  546.     XRecv;
  547. end;
  548.  
  549. procedure ChgBaud(var NBaud : integer);
  550. var
  551.   SBaud : integer;
  552.  
  553. begin
  554.   SBaud := NBaud;
  555.   Writeln;
  556.   Write('Enter new Baud Rate: ');
  557. {$I-}
  558.   Readln(SBaud);
  559. {$I+}
  560.   case SBaud of
  561.      110,
  562.      300,
  563.      600,
  564.     1200,
  565.     2400,
  566.     4800,
  567.     9600,
  568.     19200: NBaud := SBaud;
  569.   else
  570.     Write('Invalid Baud Rate, <enter> to continue');
  571.     Readln;
  572.   end;
  573. end;                                   { ChgBaud }
  574.  
  575. procedure ChgParity(var NPar : char);
  576. var
  577.   SPar : char;
  578.  
  579. begin
  580.   SPar := NPar;
  581.   Writeln;
  582.   Write('Enter new Parity: ');
  583. {$I-}
  584.   Readln(SPar);
  585. {$I+}
  586.   SPar := UpCase(SPar);
  587.   case SPar of
  588.     'O',
  589.     'E',
  590.     'N',
  591.     'M',
  592.     'S': NPar := SPar;
  593.   else
  594.     Write('Invalid Parity, <enter> to continue');
  595.     Readln;
  596.   end;
  597.  
  598. end;                                   { ChgParity }
  599.  
  600. procedure ChgData(var NData : integer);
  601. var
  602.   SData : integer;
  603.  
  604. begin
  605.   SData := NData;
  606.   Writeln;
  607.   Write('Enter new Data Bits: ');
  608. {$I-}
  609.   Readln(SData);
  610. {$I+}
  611.   case SData of
  612.      5,
  613.      6,
  614.      7,
  615.      8: NData := SData;
  616.   else
  617.     Write('Invalid Data Bits, <enter> to continue');
  618.     Readln;
  619.   end;
  620. end;                                   { ChgData }
  621.  
  622. procedure ChgStop(var NStop : integer);
  623. var
  624.   SStop : integer;
  625.  
  626. begin
  627.   SStop := NStop;
  628.   Writeln;
  629.   Write('Enter new Stop Bits: ');
  630. {$I-}
  631.   Readln(SStop);
  632. {$I+}
  633.   case SStop of
  634.      1,
  635.      2: NStop := SStop;
  636.   else
  637.     Write('Invalid Stop Bits, <enter> to continue');
  638.     Readln;
  639.   end;
  640. end;                                   { ChgStop }
  641.  
  642. procedure ChgComm;
  643. var
  644.   Sel       : char;
  645.   NBaud     : integer;
  646.   NParity   : char;
  647.   NData     : integer;
  648.   NStop     : integer;
  649.  
  650. begin
  651.   NBaud := Baud;
  652.   NParity := Parity;
  653.   NData := Databits;
  654.   NStop := Stopbits;
  655.  
  656.   repeat
  657.     ClrScr;
  658.     Writeln('-- C H A N G E   C O M M   S E T U P --');
  659.     Writeln('    presently ',NBaud, ',', NParity, ',', NData, ',', NStop);
  660.     Writeln;
  661.     Writeln('B-  change Baud rate');
  662.     Writeln('P-  change Parity');
  663.     Writeln('D-  change Data bits');
  664.     Writeln('S-  change Stop bits');
  665.     Writeln;
  666.     Writeln('A-  Abandon changes');
  667.     Writeln('Q-  Quit and install changes');
  668.     Writeln;
  669.     Write('    Enter Selection -> ');
  670.  
  671.     Sel := ReadKey;
  672.     if Sel = #0 then
  673.       Sel := ReadKey;
  674.     Sel := UpCase(Sel);
  675.  
  676.     case Sel of
  677.       'B':  ChgBaud(NBaud);
  678.       'P':  ChgParity(NParity);
  679.       'D':  ChgData(NData);
  680.       'S':  ChgStop(NStop);
  681.       'Q':  if CommSetup(CPort, NBaud, Nparity, NData, NStop) then
  682.             begin
  683.               Baud := NBaud;
  684.               Parity := NParity;
  685.               Databits := NData;
  686.               Stopbits := NStop;
  687.             end;
  688.       else
  689.       end;
  690.   until (Sel = 'A') or (Sel = 'Q');
  691. end;                                   { ChgComm }
  692.  
  693. procedure Terminal;
  694. var
  695.   Ch    : byte;
  696.   DBool : boolean;
  697.  
  698. begin
  699.   ClrScr;
  700.   while true do
  701.   begin
  702.     if LctGet(CPort,Ch) then
  703.     begin
  704.       Write(char(Ch and $7f));
  705.       if Hostm then
  706.       begin
  707.         DBool := LctPut(CPort,Ch);
  708.         if Ch = $0d then
  709.         begin
  710.           Write(char($0a));
  711.           DBool := LctPut(CPort, $0a);
  712.         end;
  713.       end;
  714.     end;
  715.  
  716.     if KeyPressed then
  717.     begin
  718.       char(Ch) := ReadKey;
  719.       if Ch = $00 then
  720.         char(Ch) := ReadKey;
  721.       if Ch = $18 then
  722.         exit;
  723.       DBool := LctPut(CPort,Ch);
  724.       if not DBool then
  725.         writeln('Put Error');
  726.       if Hostm or Halfd then
  727.       begin
  728.         Write(char(Ch));
  729.         if Ch = $0d then
  730.         begin
  731.           Write(char($0a));
  732.           if Hostm then
  733.             DBool := LctPut(CPort, $0a);
  734.         end;
  735.       end;
  736.     end;
  737.   end;
  738. end;                                   { Terminal }
  739.  
  740. procedure MainMenu;
  741. var
  742.   Sel : char;
  743.  
  744. begin
  745.   repeat
  746.     ClrScr;
  747.     Writeln('-- M A I N   M E N U --');
  748.     Writeln;
  749.     Writeln('T-  enter Terminal mode');
  750.     Writeln('    CTRL-X exits terminal mode');
  751.     Write('H-  toggles Host mode (now ');
  752.     if Hostm then
  753.       Writeln('ON)')
  754.     else
  755.       Writeln('OFF)');
  756.     Write('G-  toGgles half-duplex mode (now ');
  757.     if Halfd then
  758.       Writeln('ON)')
  759.     else
  760.       Writeln('OFF)');
  761.     Writeln('C-  change Comm settings');
  762.     Writeln('    presently ',Baud, ',', Parity, ',', Databits, ',', Stopbits);
  763.     Write('X-  change Xmodem mode (now ');
  764.     if Yxmode then
  765.       Writeln('YMODEM)')
  766.     else
  767.       Writeln('NORMAL)');
  768.     Write('W- change Windowed Xmodem mode (now ');
  769.     if Wxmode then
  770.       Writeln('ON)')
  771.     else
  772.       Writeln('OFF)');
  773.     Writeln('S-  Send a file');
  774.     Writeln('R-  Receive a file');
  775.     Writeln('Q-  Quit to DOS');
  776.     Writeln;
  777.     Write('    Select a Function -> ');
  778.  
  779.     Sel := ReadKey;
  780.     if Sel = #0 then
  781.       Sel := ReadKey;
  782. {
  783.   Dispatch Logic
  784. }
  785.     Sel := UpCase(Sel);
  786.  
  787.     case Sel of
  788.       'T':  Terminal;
  789.       'H':  begin
  790.               Hostm := not Hostm;
  791.               if Hostm then
  792.                 Halfd := false;
  793.             end;
  794.       'G':  begin
  795.               Halfd := not Halfd;
  796.               if Halfd then
  797.                 Hostm := false;
  798.             end;
  799.       'W':  Wxmode := not Wxmode;
  800.       'X':  Yxmode := not Yxmode;
  801.       'S':  SendFile;
  802.       'R':  ReceiveFile;
  803.       'C':  ChgComm;
  804.     else
  805.     end;
  806.   until Sel ='Q';
  807. end;                                   { MainMenu }
  808.  
  809. begin                                  { TTL }
  810.   CheckBreak := false;                 { disable ^C }
  811.  
  812.   if not CommOpen(CPort, Baud, Parity, Databits, Stopbits, 2000, 2000) then
  813.   begin
  814.     Writeln('Error opening Comm Port ',CPort);
  815.     Halt(1);
  816.   end;
  817.  
  818.   if SetModemSignals(Cport, (RTS or DTR)) then
  819.     MainMenu
  820.   else
  821.     Writeln('Unable to set modem signals');
  822.  
  823.   CommClose(CPort);
  824.  
  825.   ClrScr;
  826. end.
  827.